package com.blue.code.bean;

import java.util.ArrayList;
import java.util.List;

import com.blue.code.src.TableId;
import com.blue.code.util.SqlTypeConvertor;
import com.blue.core.util.ReflectionUtil;

public class EntityId extends EntityColumn
{
	protected boolean inc;

	public EntityId()
	{
	}
	
	public static EntityId toId(TableId tableId)
	{
		EntityId id = new EntityId();
		id.setName(tableId.getName());
		id.setColumn(tableId.getColumn());
		id.setField(ReflectionUtil.columnToField(id.column));
		id.setGetter(ReflectionUtil.fieldToGetter(id.field));
		id.setSetter(ReflectionUtil.fieldToSetter(id.field));
		id.setNullable(tableId.isNullable());
		id.setSize(tableId.getSize());
		id.setDef(tableId.getDef());
		id.setType(SqlTypeConvertor.sqlTypeToJava(tableId.getType()));
		id.setInc(tableId.isInc());
		return id;
	}
	
	public static List<EntityId> toId(List<TableId> list)
	{
		List<EntityId> idList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return idList;
		
		for (TableId c : list)
		{
			idList.add(toId(c));
		}
		return idList;
	}

	public boolean isInc()
	{
		return inc;
	}

	public void setInc(boolean inc)
	{
		this.inc = inc;
	}

}
